﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using Sirenix.OdinInspector;

#endif
namespace AutoChess
{
    class AutoChessConfig : MonoBehaviour
    {
        [HideInInspector] public string backAudio = string.Empty;

        #region 场景配置

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("自己船的位置"), BoxGroup("场景配置")]
#endif
        public Transform selfPos;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("敌人船的位置"), BoxGroup("场景配置")]
#endif
        public Transform targetPos;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("左方攻击曲线"), BoxGroup("场景配置")]
#endif
        public CommonAnimCurve selfHitEnemy_Curve;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("右方曲线"), BoxGroup("场景配置")]
#endif
        public CommonAnimCurve enemyHitSelf_Curve;


#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("拖拽特效材质"), BoxGroup("场景配置")]
#endif
        public Material arrowMeshMat;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("船只开进曲线"), BoxGroup("场景配置")]
#endif
        public CommonAnimCurve shipCome;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("船只离开曲线"), BoxGroup("场景配置")]
#endif
        public CommonAnimCurve shipLeave;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("默认配置的船"), BoxGroup("场景配置")]
#endif
        public int defaultShipId = 130006;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("自走棋阴影距离"), BoxGroup("场景配置")]
#endif
        public int shadowDistance = 42;

        #endregion

        #region 场景格子

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("己方格子"), BoxGroup("场景格子")]
#endif
        public ArtGridComponent selfGrid;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("敌方格子"), BoxGroup("场景格子")]
#endif
        public ArtGridComponent enemyGrid;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("被选区格子"), BoxGroup("场景格子")]
#endif
        public ArtGridComponent preChooseGrid;

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("对战中间格子"), BoxGroup("场景格子")]
#endif
        public ArtGridComponent centerGrid;
#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("场景拖拽区域格子"), BoxGroup("场景格子")]
#endif
        public ArtGridComponent dragAreaGrid;

        #endregion

        #region 战斗表现

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("英雄跳跃曲线"), BoxGroup("战斗表现")]
#endif
        public CommonAnimCurve heroJumpCurve;
#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("英雄跳跃曲线"), BoxGroup("战斗表现")]
#endif
        public CommonAnimCurve heroInGroundJumpCurve;
#if UNITY_EDITOR
        [LabelText("升星buff 在英雄入场多久展现 "), BoxGroup("战斗表现")]
#endif
        public float showStarBuff = 0.5f;
#if UNITY_EDITOR
        [LabelText("英雄入场后展现的时间"), BoxGroup("战斗表现")]
#endif
        public float showHeroTime = 1.5f;

#if UNITY_EDITOR
        [LabelText("英雄跳跃时间"), BoxGroup("战斗表现")]
#endif
        public float heroJumpTime = 0.666f;

#if UNITY_EDITOR
        [LabelText("战斗结束到打开战斗面板的时间"), BoxGroup("战斗表现")]
#endif
        public float fightEndShowResult = 0.6f;

#if UNITY_EDITOR
        [LabelText("结算面板等待时间"), BoxGroup("战斗表现")]
#endif
        public float resultPageShowTime = 3.5f;

#if UNITY_EDITOR
        [LabelText("关闭面板到播放场景结算时间"), BoxGroup("战斗表现")]
#endif
        public float closePage2SceneResult = 0.5f;

#if UNITY_EDITOR
        [LabelText("场景结算等待时间"), BoxGroup("战斗表现")]
#endif
        public float sceneShowResultTime = 1.5f;
#if UNITY_EDITOR
        [LabelText("游戏结束特效展示时间"), BoxGroup("战斗表现")]
#endif
        public float ganOverEffectTime = 2f;

#if UNITY_EDITOR
        [LabelText("进入战斗特效遮挡延时"), BoxGroup("战斗表现")]
#endif
        public float battleMaskDelayTime = 0.5f;

        #endregion

#if UNITY_EDITOR
        [Sirenix.OdinInspector.LabelText("每个船的配置")]
#endif
        public List<AutoChessShipConfig> allShipConfig = new List<AutoChessShipConfig>();

        public AutoChessShipConfig GetShipConfig(int shipModelId)
        {
            if (allShipConfig.Count > 0)
            {
                for (int i = 0; i < allShipConfig.Count; i++)
                {
                    if (allShipConfig[i].shipModelId == shipModelId)
                        return allShipConfig[i];
                }
            }

            return null;
        }

        #region 获取格子配置信息

        public int fightMapWidth = 3;
        public int fightMapHeigh = 4;
        public int preChooseMapWidth = 8;
        public int shopGridWidth = 5;

        public List<ACGridData> GetShopGridConfig()
        {
            List<ACGridData> result = new List<ACGridData>();
            int localIndex = 0;
            var pos = new Vector3(100, 100, 100);
            var size = new Vector3(0.36f, 0.89f, 1);
            var offset = new Vector3(-0.16f, 0.48f, 0);

            for (int c = 0; c < shopGridWidth; c++)
            {
                var data = new ACGridData(GridType.ShopGrid, 0, c, localIndex++,
                    pos, size, offset);
                result.Add(data);
            }

            return result;
        }

        public List<ACGridData> GetFightGridConfig()
        {
            List<ACGridData> result = new List<ACGridData>();
            var size = new Vector3(selfGrid.Size.x,0,selfGrid.Size.y);
            int localIndex = 0;

            for (int r = 0; r < fightMapHeigh; r++)
            {
               for (int c = 0; c < fightMapWidth; c++)
               {
                   var data = new ACGridData(GridType.FightGrid,r,c,localIndex++,
                           selfGrid.GridPos[r,c],size,Vector3.zero);
                   result.Add(data);
               }
            }

            return result;
        }
            
         public List<ACGridData> GetEnemyGridConfig()
         {
             List<ACGridData> result = new List<ACGridData>();
             var size = new Vector3(enemyGrid.Size.x,0,enemyGrid.Size.y);
             int localIndex = 0;

             for (int r = 0; r < fightMapHeigh; r++)
             { 
                 for (int c = 0; c < fightMapWidth; c++)
                 { 
                    var data = new ACGridData(GridType.EnemyGrid,r,c,localIndex++,
                                            enemyGrid.GridPos[r,c],size,Vector3.zero);
                     result.Add(data);
                 }
             }

             return result;
         }
            
            public List<ACGridData> GetPreChooseGridConfig()
            {
                    List<ACGridData> result = new List<ACGridData>();
                    var size = new Vector3(preChooseGrid.Size.x,0.1f,preChooseGrid.Size.y);
                    int localIndex = 0;

                    for (int c = 0; c < preChooseMapWidth; c++)
                    { 
                        var data = new ACGridData(GridType.PreChooseGrid,0,c,localIndex++,
                                preChooseGrid.GridPos[0,c],size,Vector3.zero);
                        result.Add(data);
                    }

                    return result;
            }
            
            public List<ACGridData> GetCenterGridConfig()
            {
                    List<ACGridData> result = new List<ACGridData>();
                    var size = new Vector3(centerGrid.Size.x,0.1f,centerGrid.Size.y);
                    int localIndex = 0;

                    for (int c = 0; c < 3; c++)
                    { 
                        var data = new ACGridData(GridType.CenterGrid,0,c,localIndex++,
                                    centerGrid.GridPos[0,c],size,Vector3.zero); 
                        result.Add(data);
                    }

                    return result;
            }  
            #endregion
    }
}